This session walks through tons of examples in live coding. You will learn everything you need to know about lambdas and functional programming in Java 8. I’m the supplier. You’re the consumer (and you will get the joke after the session).
11. 11
JAVA 5 GAVE THE GENERIC
TYPES TO THE WORLD
(and also annotations, concurrent collections, enum types, for
each, static imports and so on and so on)
12. 12
Type witness
Having
<T> T anyObject()
you can force the type with
MyClass.<List<String>> anyObject()
because
(List<String>) MyClass.anyObject()
gives a warning
21. 21
Auto Closeable
Before
InputStream in = new FileInputStream("allo.txt");
try {
// … do stuff
} finally {
try { in.close(); } catch(IOException e) {}
}
After
try(InputStream in = new FileInputStream("allo.txt")) {
// … do stuff
}
24. 24
JAVA 8: LAMBDA!
(and also a new date API, default methods, metaspace, Nashorn,
JavaFX and CompletableFuture)
25. 26
Date / Time API
Core ideas:
Immutable
A time is a time, a date is a date. Not always both (like java.util.Date)
Not everyone uses the same calendar (the same Chronology)
LocalDate, LocalTime, LocalDateTime Local. No time zone
OffsetDateTime, OffsetTime Time with an offset from
Greenwich
ZonedDateTime LocalDateTime with a time zone
Duration, Period Time span
Instant Timestamp
Formatting Easy and thread-safe formatting
26. 27
Date / Time API (example)
LocalDateTime now = LocalDateTime.now();
String thatSpecialDay = now
.withDayOfMonth(1)
.atZone(ZoneId.of("Europe/Paris"))
.plus(Duration.ofDays(5))
.format(DateTimeFormatter.ISO_ZONED_DATE_TIME);
System.out.println(thatSpecialDay);
Output
2016-09-06T17:45:22.488+01:00[Europe/Paris]
29. 30
(also written as λ-calculus) is a formal system in
mathematical logic for expressing computation based
on function abstraction and application using variable
binding and substitution. It is a universal model of
computation that can be used to simulate any single-
taped Turing machine and was first introduced by
mathematician Alonzo Church in the 1930s as part of
an investigation into the foundations of mathematics.
Lambda calculus
30. 31
This is a function:
This is a lambda:
Lambda calculus
35. 47
Brian Goetz – State of the lambda
http://cr.openjdk.java.net/~briangoetz/lambda/lambda-state-
final.html
http://cr.openjdk.java.net/~briangoetz/lambda/lambda-
translation.html
Ninja Squad – Lambda Kata
https://github.com/Ninja-Squad/ninjackaton-lambda
Maurice Naftalin’s lambda facts and books
http://www.lambdafaq.org/
Mastering Lamdbas: Java Programming in a Multicore World
Links